package com.busi.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.Random;

public class FileUtil {
	/**
	 * ********************************************
	 * method name   : getFileName 
	 * description   : 
	 * @return       : String
	 * @param        : @param ori_fileName
	 * @param        : @return
	 * modified      : dmm ,  2016-11-17  下午2:06:17
	 * @see          : 
	 * *******************************************
	 */
	public static String getFileName(String ori_fileName){
		String fileExt = ori_fileName.substring(ori_fileName.lastIndexOf(".")).toLowerCase();  
		int r = new Random().nextInt(10000);
		String fileName = CodesUtil.encodeMD5(ori_fileName + System.currentTimeMillis() + r) + fileExt;
		return fileName;
	}

    public static void fileCopy(File s, File t) {

        FileInputStream fi = null;
        FileOutputStream fo = null;
        FileChannel in = null;
        FileChannel out = null;
        try {
            fi = new FileInputStream(s);
            fo = new FileOutputStream(t);
            in = fi.getChannel();// 得到对应的文件通道
            out = fo.getChannel();// 得到对应的文件通道
            in.transferTo(0, in.size(), out);// 连接两个通道，并且从in通道读取，然后写入out通道
        } catch (IOException e) {
        	e.printStackTrace();
        } finally {
            try {
                fi.close();
                in.close();
                fo.close();
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    public static void main(String[] args) {
		System.out.println(getFileName(""));
	}
    
    
    
}